package ms.platform.system.service;

import java.util.HashSet;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import ms.platform.system.dao.ResourceDAO;
import ms.platform.system.model.Menu;
import ms.platform.system.model.Resource;
import ms.platform.system.model.RoleResource;

@Service
@Transactional(propagation=Propagation.SUPPORTS)
public class ResourceService {

	@Autowired
	private ResourceDAO resourceDAO;
	
	/*public HashSet<Resource> getAllResourceByAdminId(Integer id) {
		return resourceDAO.getAllResourceByAdminId(id);
	}*/

	/**
	 * 获取资源列表list
	 * @return
	 */
	public List<Resource> queryResourceList() {
		return resourceDAO.queryResourceList();
	}
	
	/**
	 * 获取启用资源列表list
	 * @return
	 */
	public List<Resource> queryUsedResourceList() {
		return resourceDAO.queryUsedResourceList();
	}
	
	/**
	 * 根据id查询权限
	 * @param id
	 * @return
	 */
	public Resource queryResourceById(Integer id){
		return resourceDAO.queryResourceById(id);
	}
	
	/**
	 * 根据id删除资源
	 * @param id
	 */
	public void deleteResourceById(Integer id){
		 resourceDAO.deleteResourceById(id);
	}
	
	public void updateResource(Resource  resource){
		 resourceDAO.updateResource(resource);
	}
	
	/**
	 * 修改启用/禁用状态 
	 * @param resource
	 */
	public void disabledResource(Resource  resource){
		resourceDAO.updateResourceById(resource);
	}
	
	public void insertResource(Resource  resource){
		 resourceDAO.insertResource(resource);
	}
	
	public List<Menu> getAllMenuByAdminId(Integer id) {
		return resourceDAO.getAllMenuByAdminId(id);
	}

	/**
	 * 根据roleId查询该角色的权限列表
	 * @param id
	 * @return
	 */
	public List<Resource> queryResourceByRole(Integer id) {
		return resourceDAO.queryResourceByRole(id);
	}
	
	public List<RoleResource>  queryRoleResource(RoleResource roleResource){
		return resourceDAO.queryRoleResource(roleResource);
	}
	
	public void insertRoleResource(RoleResource roleResource){
		resourceDAO.insertRoleResource(roleResource);
	}
	
	public void deleteRoleResource(RoleResource roleResource){
		resourceDAO.deleteRoleResource(roleResource);
	}
	
	public void deleteRoleResourceById(Integer roleId){
		resourceDAO.deleteRoleResourceById(roleId);
	}
	public void orderResource(RoleResource roleResource){
		resourceDAO.orderResource(roleResource);
	}

	public HashSet<String> getAllResourceUrlByAdminId(Integer id) {
		return resourceDAO.getAllResourceUrlByAdminId(id);
	}
	
	/**
	 * 查询‘登陆’，‘退出’，‘首页’三个系统资源的id
	 */
	public List<Integer> queryResourceIdList(){
		return resourceDAO.queryResourceIdList();
	}
	
}
